<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"
%><%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"
%><%@ taglib prefix="security" uri="http://www.springframework.org/security/tags"
%><%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"
%><%@ taglib prefix="tags" tagdir="/WEB-INF/tags"
%><%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"
%>
<c:if test="${includeBody}">
<head>
    <title><fmt:message key="contentlet" /></title>
</head>
<body>
</c:if>
    <c:url var="searchUrl" value="/domain/contentlet/searchAjax"/>
	<div id="contentletSearchFormFragment">
    <form:form action="${searchUrl}" modelAttribute="contentletSearchForm">
        <table>
            <tbody>
				<!-- Current selected structure. -->
				<form:hidden path="structureInode" />
				<c:forEach items="${fields}" var="field" varStatus="status">
				<c:if test="${status.count % 2 == 1}">  
				<tr>  
				</c:if>    
					<th><c:out value="${field.fieldName}" /></th>
					<td>
					<c:choose>
						<c:when test="${field.fieldType == 'text'}">
						<input type="text" name="${field.velocityVarName}" id="${field.velocityVarName}"/>
						<script type="text/javascript">
							Spring.addDecoration(new Spring.ElementDecoration({
								elementId : "${field.velocityVarName}",
								widgetType : "dijit.form.ValidationTextBox",
								widgetAttrs : {
									required: false
								}
							}));
						</script>
						</c:when>
						<c:when test="${field.fieldType == 'textarea'}">
						<input type="text" name="${field.velocityVarName}" id="${field.velocityVarName}"/>
						<script type="text/javascript">
							Spring.addDecoration(new Spring.ElementDecoration({
								elementId : "${field.velocityVarName}",
								widgetType : "dijit.form.ValidationTextBox",
								widgetAttrs : {
									required : false
								}
							}));
						</script>
						</c:when>
						<c:when test="${field.fieldType == 'category'}">
						<select name="${field.velocityVarName}" id="${field.velocityVarName}">
							<!-- Find the key which hold the options value. -->
							<c:forEach items="${categoryMap}" var="map" >
								<c:if test="${map.key == field.velocityVarName}">
									<c:forEach items="${map.value}" var="value">
										<option value="${value.key}">${value.value}</option>
									</c:forEach>
								</c:if>
							</c:forEach>
						</select>
						<script type="text/javascript">
							Spring.addDecoration(new Spring.ElementDecoration({
								elementId : "${field.velocityVarName}",
								widgetType : "dijit.form.FilteringSelect",
								widgetAttrs : {
									required : false
								}
							}));
						</script>
						</c:when>


						<c:when test="${field.fieldType == 'checkbox'}">
						<input type="checkbox" name="${field.velocityVarName}" id="${field.velocityVarName}" value="true">
						<script type="text/javascript">
							Spring.addDecoration(new Spring.ElementDecoration({
								elementId : "${field.velocityVarName}",
								widgetType : "dijit.form.CheckBox",
								widgetAttrs : {
								}
							}));
						</script>
						</c:when>


						<c:when test="${field.fieldType == 'date'}">
						<input type="text" name="${field.velocityVarName}" id="${field.velocityVarName}">
						<script type="text/javascript">
							Spring.addDecoration(new Spring.ElementDecoration({
								elementId : "${field.velocityVarName}",
								widgetType : "dijit.form.DateTextBox",
								widgetAttrs : {
									//label: '${field.fieldValues}'
								}
							}));
						</script>
						</c:when>
					</c:choose>
					</td>
				<c:if test="${((status.count)) % 2 == 0}">  
				</tr>  
				</c:if>  
				</c:forEach>
            </tbody>
            <tfoot>
                <tr>
                    <td colspan="4">
                        <div class="buttons">
                            <button id="searchButtonEx" type="submit"><fmt:message key="label.search.submit" /></button>
                            <script type="text/javascript">
                                Spring.addDecoration(new Spring.ValidateAllDecoration({
                                    elementId:'searchButtonEx',
                                    event:'onclick'
                                }));
								Spring.addDecoration(new Spring.AjaxEventDecoration({
									elementId: "searchButtonEx",
									event: "onclick",
									formId: "contentletSearchForm",
									params: { decorator: "none" }
								}));
                            </script>
                        </div>
                    </td>
                </tr>
            </tfoot>
        </table>
    </form:form>				
	</div>
	<h2><fmt:message key="searchResult" />${structure.name}</h2>
	<jsp:include page="/WEB-INF/views/domain/contentlet/searchEmptyResult.jsp" flush="true">
		<jsp:param name="includeBody" value="true" />
	</jsp:include>
<c:if test="${includeBody}">
</body>
</c:if>